package org.jivesoftware.smack.util;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

public class ObservableWriter extends Writer
{
  List listeners;
  Writer wrappedWriter = null;

  public ObservableWriter(Writer paramWriter)
  {
    this.listeners = new ArrayList();
    this.wrappedWriter = paramWriter;
  }

  // ERROR //
  private void notifyListeners(String paramString)
  {
    // Byte code:
    //   0: aconst_null
    //   1: checkcast 24	[Lorg/jivesoftware/smack/util/WriterListener;
    //   4: pop
    //   5: aload_0
    //   6: getfield 20	org/jivesoftware/smack/util/ObservableWriter:listeners	Ljava/util/List;
    //   9: astore_3
    //   10: aload_3
    //   11: monitorenter
    //   12: aload_0
    //   13: getfield 20	org/jivesoftware/smack/util/ObservableWriter:listeners	Ljava/util/List;
    //   16: invokeinterface 30 1 0
    //   21: anewarray 32	org/jivesoftware/smack/util/WriterListener
    //   24: astore 5
    //   26: aload_0
    //   27: getfield 20	org/jivesoftware/smack/util/ObservableWriter:listeners	Ljava/util/List;
    //   30: aload 5
    //   32: invokeinterface 36 2 0
    //   37: pop
    //   38: aload_3
    //   39: monitorexit
    //   40: iconst_0
    //   41: istore 7
    //   43: iload 7
    //   45: aload 5
    //   47: arraylength
    //   48: if_icmplt +11 -> 59
    //   51: return
    //   52: astore 4
    //   54: aload_3
    //   55: monitorexit
    //   56: aload 4
    //   58: athrow
    //   59: aload 5
    //   61: iload 7
    //   63: aaload
    //   64: aload_1
    //   65: invokeinterface 39 2 0
    //   70: iinc 7 1
    //   73: goto -30 -> 43
    //
    // Exception table:
    //   from	to	target	type
    //   12	40	52	finally
    //   54	56	52	finally
  }

  public void addWriterListener(WriterListener paramWriterListener)
  {
    if (paramWriterListener == null)
      return;
    synchronized (this.listeners)
    {
      if (!(this.listeners.contains(paramWriterListener)))
        this.listeners.add(paramWriterListener);
    }
  }

  public void close()
    throws IOException
  {
    this.wrappedWriter.close();
  }

  public void flush()
    throws IOException
  {
    this.wrappedWriter.flush();
  }

  public void removeWriterListener(WriterListener paramWriterListener)
  {
    synchronized (this.listeners)
    {
      this.listeners.remove(paramWriterListener);
      return;
    }
  }

  public void write(int paramInt)
    throws IOException
  {
    this.wrappedWriter.write(paramInt);
  }

  public void write(String paramString)
    throws IOException
  {
    this.wrappedWriter.write(paramString);
    notifyListeners(paramString);
  }

  public void write(String paramString, int paramInt1, int paramInt2)
    throws IOException
  {
    this.wrappedWriter.write(paramString, paramInt1, paramInt2);
    notifyListeners(paramString.substring(paramInt1, paramInt1 + paramInt2));
  }

  public void write(char[] paramArrayOfChar)
    throws IOException
  {
    this.wrappedWriter.write(paramArrayOfChar);
    notifyListeners(new String(paramArrayOfChar));
  }

  public void write(char[] paramArrayOfChar, int paramInt1, int paramInt2)
    throws IOException
  {
    this.wrappedWriter.write(paramArrayOfChar, paramInt1, paramInt2);
    notifyListeners(new String(paramArrayOfChar, paramInt1, paramInt2));
  }
}